﻿

function main() {
    showLog("抖音(推荐回复)");
    var testVersion = "(201901021555)版";
    var softwareName = "抖音";
    var view = RequestEngine.getWebView();
    var viewJson = JSON.parse(view);
    var search = viewJson.search;
    var terminationNum = viewJson.terminationNum;
    var contentArr = viewJson.contentArr;
    AccessibilityEngine.sleepEngine(8000);//等待
	if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
    }
    if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
        AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
    }
	
	
    var jixing = getXYByIdIndex(widget.pages.shouye.wode);
    ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
   

    for (var i =0 ; i <search; i ++ ){  // 循环滑动
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
			}
			if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
				AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
			}
	
		
            AccessibilityEngine.sleepEngine(1000);//等待
            if( jixing == 1 ){// 判断机型
                var pressjixing = "press," + parseX(660) + "," + parseY(757);
                ScreenEngine.currency(pressjixing);
            } else if( jixing == 2 ){
                ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
            }
            for (var ii=0 ; ii<=10 ;ii++){// 判断是否进入评论区
                if ( AccessibilityEngine.checkUpText("留下你的精彩评论吧") == ISFALSE){
                    if( jixing == 1 ){
                        var pressjixing = "press," + parseX(660) + "," + parseY(763);
                        ScreenEngine.currency(pressjixing);
                    } else if( jixing == 2 ){
                        ScreenEngine.swipe(parseX(667), parseY(760), parseX(667), parseY(760), 500); //从下往上滑动
                    }
                }else {
                    break;
                }
                if (ii==15){
                    setTaskState("5", "脚本执行完毕");
                    throw SyntaxError();
                }
            }
            if (AccessibilityEngine.checkUpIdText(widget.pages.fasongxiaoxi.plzf, "评论并转发")==ISTRUE){
                showLog("误点评论返回");
                i--;
                AccessibilityEngine.mockBack();
                AccessibilityEngine.sleepEngine(2000);//等待
                AccessibilityEngine.mockBack();
                AccessibilityEngine.sleepEngine(2000);//等待
                ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
                continue;
            }

            var termination=0;
            var neirongList = [];
            var flagAdd=0;
            aaa:while (termination < terminationNum){
					if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
						AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
					}
					if (AccessibilityEngine.checkUpId(widget.pages.shouye.wzdl) == ISTRUE) { //我知道了
						AccessibilityEngine.mockOnClickId(widget.pages.shouye.wzdl);
					}
	
                if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) { //点评论区
				
					if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
						AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
					}
                    var nameIdNum = AccessibilityEngine.getIdNum(widget.pages.pinglun.titleneirong);
                    showLog('nameIdNum' + nameIdNum);
                    for (var name = 0; name < nameIdNum; name++) {
                        var JSONneirong =  AccessibilityEngine.getBoundsCenterIdIndex(widget.pages.pinglun.titleneirong,name);
                        neirongList.push(JSONneirong);
                    }
                    for (var nameI = 0; nameI < neirongList.length; nameI++) {
                        var neirongListJSON=JSON.parse(neirongList[nameI]);
                        showLog(neirongListJSON);
                        var neirongListJSONcenterX=parseInt(neirongListJSON.centerX)+200;
                        showLog(neirongListJSONcenterX);
                        showLog(neirongListJSON.centerY);
                        if (jixing == 1) {
                            if (neirongListJSON.centerY > 1100) {
                                showLog('错误点击');
                                continue;
                            }
                        }else {
                            if (neirongListJSON.centerY > 1500) {
                                showLog('错误点击');
                                continue;
                            }
                        }			
						
						
						if( jixing == 1 ){
                          ScreenEngine.swipe(parseX(305), parseY(345), parseX(305), parseY(345), 500); //点击 
                                  } else if( jixing == 2 ){
                           ScreenEngine.swipe(parseX(330), parseY(535), parseX(330), parseY(535), 500); //点击	
                              }
			  
                        var pressCenter = "press," + neirongListJSONcenterX + "," + neirongListJSON.centerY;
                        ScreenEngine.currency(pressCenter);
                        AccessibilityEngine.sleepEngine(2000);//等待
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                        if (AccessibilityEngine.checkUpId(widget.pages.shouye.fasong) == ISTRUE) {
                            showLog('3333')
                        }   else {
                            if (AccessibilityEngine.checkUpIdText(widget.classText.widgetByClass.text1, "回复") == ISTRUE) {
                                showLog('1111')
                                if (jixing == 1) {
                                    AccessibilityEngine.mockOnClickIdIndex(widget.classText.widgetByClass.text1, 0);
                                } else if ( jixing == 2 ){
                                    var presshuifu = "press," + parseX(511 * 0.67) + "," + parseY(700 * 0.67);
                                    ScreenEngine.currency(presshuifu);
                                }
                            }else {
                                showLog('2222')
                                if (AccessibilityEngine.checkUpIdText(widget.classText.widgetByClass.text1, "删除") == ISTRUE) {
                                    AccessibilityEngine.mockBack();
                                    continue;
                                }else  if (AccessibilityEngine.checkUpId(widget.pages.shouye.pinglunKuang) == ISFALSE) {
                                    AccessibilityEngine.mockBack();
                                    if (AccessibilityEngine.checkUpId(widget.pages.pinglun.fanhui1) == ISTRUE) {
                                        AccessibilityEngine.mockOnClickId(widget.pages.pinglun.fanhui1);
                                        showLog('广告详情返回2');
                                        if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE) {
                                            AccessibilityEngine.mockBack();
                                        }
                                    }
                                    break aaa;
                                }
                            }
                        }
                        AccessibilityEngine.sleepEngine(2000);//等待
						if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
							AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
						}
                        if (AccessibilityEngine.checkUpId(widget.pages.shouye.fasong) == ISTRUE) {
							if (AccessibilityEngine.checkUpId(widget.pages.shouye.bugengxin) == ISTRUE) { //更新以后再说
								AccessibilityEngine.mockOnClickId(widget.pages.shouye.bugengxin);
							}
							
                            showLog("pinglunKuang ");
                            var search2 = contentArr[Math.floor(Math.random()*contentArr.length)];
                            showLog(search2+"search2");
							
							
                            AccessibilityEngine.mockEditId(widget.pages.shouye.pinglunKuang,search2); //赋值
							
							
                            AccessibilityEngine.sleepEngine(1000);//等待
                            showLog("赋值 ");
                            AccessibilityEngine.mockOnClickId(widget.pages.shouye.fasong); // 发送
                            AccessibilityEngine.sleepEngine(2000);//等待
                            showLog("发送 ");
                            if (AccessibilityEngine.getEditText(widget.pages.shouye.pinglunKuang)==search2){
                                flagAdd++;
                                if (flagAdd >= 2) {
                                    setTaskState("5", "已经撩过了或者发言过快");
                                    throw SyntaxError();
                                }
                                AccessibilityEngine.mockBack();
                            }
                            termination++;
                            if (termination>=terminationNum){
                                AccessibilityEngine.mockBack();
                                break aaa;
                            }
                        }else {
                            showLog("pinglunKuangFalse ");
                            AccessibilityEngine.mockBack();
                            continue;
                        }
                    }
                    if (AccessibilityEngine.checkUpText("暂时没有更多了") == ISTRUE 　) {
                        showLog("暂时没有更多了点击返回");
                        AccessibilityEngine.mockBack();
                        break  aaa;
                    }
                    showLog("滑动滑动滑动");
                    ScreenEngine.swipe(parseX(450), parseY(1100), parseX(450), parseY(200), 500);
                }else {
                    showLog('wode');
                    AccessibilityEngine.mockBack();
                    break aaa;
                }
            }
            if (AccessibilityEngine.checkUpId(widget.pages.pinglun.titleneirong) == ISTRUE || AccessibilityEngine.checkUpText("暂无评论") == ISTRUE ) {
                AccessibilityEngine.mockBack();
            }
            ScreenEngine.swipe(parseX(300), parseY(1000), parseX(300), parseY(200), 500); //从下往上滑动
        }
showLog("显示执行成功");
setTaskState("5", "脚本执行完毕");
throw SyntaxError();

}
var publicfunction = RequestEngine.getPluginPath() + "OS_DYCOMMON/publicfunction.js";
include(publicfunction); //公共方法js
var widgetPath = dyConditionCheck();
var widgetbyid = RequestEngine.getPluginPath() +"OS_DYCOMMON/"+ widgetPath;
include(widgetbyid);
main();